#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2024/3/6 16:17
# @Author  : jize.liu
# @File    : MAYA插件文件夹创建.py
# @声明     : 版权由 刘继泽 所有,如有疑问，需要帮助请联系刘继泽
import os , shutil
import random
from PIL import Image
path = "T:/ANI_Team/TX/207个手绘发光线条霓虹闪烁动画素材-png"
for  i in os.listdir(path):
    picPath = os.path.join(path,i)
    for pic in os.listdir (picPath):
        picPathAll = os.path.join(picPath,pic)
        sequencePath = os.path.join(picPath,"sequence")
        if not os.path.exists (sequencePath) :
            os.mkdir (sequencePath)
        if os.path.exists (picPathAll):

            shutil.move (picPathAll , sequencePath)
            file_list = sorted (os.listdir (sequencePath))  # 获取文件列表并按名称进行排序
        if len (file_list) >= 30 :  # 确保至少有10个文件存在于文件夹中
            tenth_file = file_list[15]  # 索引从0开始计数，所以第十个文件对应索引9
            print("aaaaaaaaaaa")
            image = Image.open (os.path.join (sequencePath , tenth_file))
        elif len (file_list) > 10 and len (file_list) <20:  # 确保至少有10个文件存在于文件夹中
            tenth_file = file_list[7]  # 索引从0开始计数，所以第十个文件对应索引9
            print ("bbbbbbbbb")
            image = Image.open (os.path.join (sequencePath , tenth_file))
        elif len (file_list) >5  and len (file_list) < 10:  # 确保至少有10个文件存在于文件夹中
            tenth_file = file_list[5]  # 索引从0开始计数，所以第十个文件对应索引9
            print ("cccccccccc")
            image = Image.open (os.path.join (sequencePath , tenth_file))
        elif len (file_list) < 5:  # 确保至少有10个文件存在于文件夹中
            pass


        resized_image = image.resize ((800,500))
        rgb_im = resized_image.convert ('RGB')
        rgb_im.save (os.path.join(picPath,"thumbnail.jpg"))

        #shutil.copy (os.path.join(sequencePath,tenth_file), os.path.join(picPath,"thumbnail.jpg"))



'''
def resize_image(input_path , output_path , new_size) :
    # 打开原始图像文件
    image = Image.open (input_path)

    # 调整图像大小并保存到新路径
    resized_image = image.resize (new_size)
    resized_image.save (output_path)


# 输入参数为原始图像路径、目标图像路径和新的宽度高度（元组形式）
input_file = "original_image.jpg"
output_file = "resized_image.jpg"
new_width = (200 , 150)'''